package net.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @author 王霄
 * @date 2021/8/27 20:57
 */

public class NioClient2 {
    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", 6666);
        if (!socketChannel.connect(address)) {
            while (!socketChannel.finishConnect()) {
                System.out.println("连接中......非阻塞");
            }
        }
        ByteBuffer buffer = ByteBuffer.wrap("你好".getBytes());
        socketChannel.write(buffer);
        System.in.read();
    }
}
